package com.example.android_demo2.workmanager

import android.os.Bundle
import android.util.Log
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import com.example.android_demo2.databinding.ActivityWorkManagerBinding

class WorkManagerActivity : AppCompatActivity() {

    private val viewModel: WorkManagerViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ActivityWorkManagerBinding.inflate(layoutInflater).run {
            setContentView(root)
            bindView(this)
        }
        viewModel.workInfo.observe(this, Observer { info ->
            if (info != null) {
                Log.e("aaaddd", "info+++$info")
            }
            var outputData = info[0].outputData
            outputData.getString("IMAGE_DATA")?.let {
                Log.e("aaaddd", "outputData++++$it")
            }
        })
    }

    private fun bindView(binding: ActivityWorkManagerBinding) {
        with(binding) {

            button.setOnClickListener {
                viewModel.applyWorker()
            }
        }

    }
}